package cn.kgc.controller;

import cn.kgc.pojo.Quality;
import cn.kgc.service.QualityService;
import cn.kgc.utils.PageInfo;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/kongqi")
public class KqController {
    private Logger logger = Logger.getLogger(KqController.class);

    @Resource
    QualityService service;

    @RequestMapping("/kongqi1")
    public String limit(@RequestParam(value = "currentPageNo", required = false) Integer currentPageNo,
                        @RequestParam(value = "pageSize", required = false) Integer pageSize,
                        @RequestParam(value = "name", required = false) String name,
                        Model model) {

        PageInfo pageInfo = new PageInfo();
        if (currentPageNo != null) {
            pageInfo.setCurrentPageNo(currentPageNo);
        }
        if (pageSize != null) {
            pageInfo.setPageSize(pageSize);
        }
        int totalCount = service.getCount(name);
        logger.info("===============" + totalCount);
        pageInfo.setTotalConut(totalCount);

        List<Quality> list = service.getByPage(pageInfo.getCurrentPageNo(), pageInfo.getPageSize(), name);
        pageInfo.setData(list);
        model.addAttribute("page1", pageInfo);
        model.addAttribute("name", name);
        return "index";
    }
}
